@extends('backstage.layout.master')
@include('UEditor::head')
@section('title', '推送页面')
@section('style')
        <!-- page specific plugin styles -->
<link rel="stylesheet" href="backstage/assets/css/jquery-ui-1.10.3.custom.min.css"/>
<link rel="stylesheet" href="backstage/assets/css/chosen.css"/>
<link rel="stylesheet" href="backstage/assets/css/datepicker.css"/>
<link rel="stylesheet" href="backstage/assets/css/bootstrap-timepicker.css"/>
<link rel="stylesheet" href="backstage/assets/css/daterangepicker.css"/>
<link rel="stylesheet" href="backstage/assets/css/colorpicker.css"/>

<!-- fonts -->
<style>
    .ace-file-input input[type=file]{
        position:static;
    }
    .ace-nav {
        height: 10px;
    }
    #container_id{
        align-content: center;
    }
	
</style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>
            <li class="active">
                <a href="/backstage/jpush/showpushhtml">推送页面</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        推送
                        <small>
                            <i class="icon-double-angle-right"></i>
                            推送页面
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="form-horizontal">
							<div class="form-group {{$errors->first('title')!=''?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 推送平台 </label>
                                <div id="plat" class="col-sm-4">
                                    <a>
										<input type="checkbox" name="check-box" value="ios" style="margin-top:9px;"/> 
										<span style="margin-right: 5px;">IOS</span>
										<input type="checkbox" name="check-box" value="android" style="margin-top:9px;"/>
										<span>Android</span>
									</a>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> 若不选默认为所有平台</div>
                                </div>
                            </div>
                            <div class="form-group {{$errors->first('title')!=''?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 标题 </label>
                                <div class="col-sm-4">
                                    <input type="text"id="title" name="title" value="" id="form-field-1" placeholder="标题"
                                           class="width-100"><span color="red">推送时最多只显示58个汉字</span>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('title')}}</div>
                                </div>
                            </div>
							<div class="form-group {{$errors->first('title')!=''?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 链接 </label>
                                <div class="col-sm-4">
                                    <input type="text"id="url" name="url" value="" id="form-field-1" placeholder="标题"
                                           class="width-100"><span color="red">如填写链接则无需编辑页面</span>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('title')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('description')!=""?'has-error':''}}" id="container_id">
                                <div class="space-4"></div>
                                <div class="col-sm-4"  style="display: none">
                                    <script id="container" name="content" type="text/plain" >
                                    </script>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('description')}}</div>
                                </div>
                            </div>

                            <div class="clearfix form-actions"  style="display: none">
                                <div class="col-md-offset-5 col-md-9">
                                    <button class="btn btn-info" id="savehtml">
                                        <i class="icon-ok bigger-110"></i>
                                        保存
                                    </button>
                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset" onclick="window.location.reload();">
                                        <i class="icon-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
	
    <script type="text/javascript">
        $(function () {
            $('#cover_image').ace_file_input({
                no_file: '还未选择图片',
                btn_choose: '选择',
                btn_change: '重新选择',
                droppable: false,
                onchange: null,
                thumbnail: true //| true | large
            });
            var editor = new UE.ui.Editor({ initialFrameWidth:1000 ,
                initialFrameHeight:500
            });
            $('#container').css("align","center");
            editor.render("container");
            var ue = UE.getEditor('container');
            ue.ready(function() {
                $("#edui1").addClass("col-sm-offset-2 ");
                var form_w=$("#container_id").width();
                var  margin_left=(form_w-1010)/2;
                var  margin_left_str=margin_left+"px";
                var t=$("#edui1").css("margin-left",margin_left_str);
                $(".col-sm-4").show();
                $(".form-actions").show();
                ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
            });
			$("#savehtml").click(function(){
				swal({
					title:"确认推送吗？",
					text:"",
					type:"warning",
					showCancelButton: true,
					confirmButtonColor: "#DD6B55",
					confirmButtonText: "确定",
					cancelButtonText:"取消",
					closeOnConfirm: false,
					closeOnCancel: true
				},function(){
						var title	= $("#title").val().trim();
						var url		= $("#url").val().trim();
						var body	= UE.getEditor('container').getContent();
						
						var arrobj	= new Array();
						$("#plat input[name=check-box]:checked").each(function(){
							arrobj.push($(this).val());
						});
						if(arrobj==null||arrobj==""){
							arrobj	= 0;
						}
						
						if(title==""){
							swal('请输入标题','','warning');
							return;
						}
						if(body==""&&url==""){
							swal('请输入内容或链接','','warning');
							return;
						}
						$.ajax({
							url:"/backstage/jpush/pushhtml",
							type:"post",
							data:{"title":title,"body":body,'plat':arrobj,'url':url},
							datatype:"json",
							success:function(re){
								if(re.state=="M00000"){
									swal(re.message,'','success');
									//window.location.reload();
									return;
								}
								swal(re.message,'','warning');
							},
							error:function(){
								swal('','系统繁忙，请稍后再试','warning');
							}
						});
				});				
				
			});
//            $('#reset_id').click(function(){
//                var str=UE.getEditor('container').execCommand( "getlocaldata" );
//            });
        });
    </script>
@stop